Ext.namespace('GBIF');
GBIF.CenterPanel = function(config){
	
	this.associationGrid = new GBIF.AssociationGrid({
			region: 'east'
		,	width: 400
		,	split: true
		,	minSize: 350
        ,	maxSize: 450
	});
	
	this.ssGrid = new GBIF.SSGrid({
			region: 'center'
	});
	
	this.associationGrid.on('afterAssocDelete', this.afterAddDelete, this);
	this.ssGrid.on('afterAssocAdd', this.afterAddDelete, this);
	this.ssGrid.on('rowselected', function(rec, me){
		this.associationGrid.store.baseParams ={
				term: rec.data.query
			,	cmd: 'listAssociation'
			,	limit: this.associationGrid.pageSize
		};
		GBIF.currentTerm = rec.data.query;
		this.associationGrid.store.reload();
	},this);
	
	this.ssGrid.on('rowdeselected', function(rec, me){
		this.associationGrid.store.removeAll();
	},this);
	
	Ext.apply(this, config, {
			region: 'center'
		,	layout: 'border'
		,	border: false
		,	items: [this.associationGrid, this.ssGrid]
	});
	
	GBIF.CenterPanel.superclass.constructor.call(this, config);
};
Ext.extend(GBIF.CenterPanel, Ext.Panel, {
	afterAddDelete: function(){
		this.ssGrid.store.reload();
		this.ssGrid.getSelectionModel().clearSelections()
		this.associationGrid.store.removeAll();
	}
});